<template>
	<view style="height: 100vh;position: relative;" class="content theme_bg_vice_color">
		<z-paging ref="paging" v-model="dataList" use-page-scroll @query="queryList" >
			<view slot="top" class="theme_bg_color">
				<cu-custom id="nav" :isdw="true" > 
				<!-- :bgColor="'bg-080808'" -->
					<block slot="dw">
						<view class="flex">
							<view class="dwt">剧本列表</view>
						</view>
					</block>
				</cu-custom>
				<view id="head" class="theme_bg_color theme_text_color" style="font-size: 26rpx;">
					<van-search shape="round" background="#fff" @search="search" @change="searchChange"
						placeholder="输入剧本名,快速找到哈" />
					<scroll-view scroll-x="true" class="scroll-view_H padding-lr padding-tb-xs"
						v-for="(item,index) in menuList" :key="index" v-if="index<3">
						<!-- <view class="scroll-view-item_H box_whbrc">全部</view> -->
						<view @click="selectTag(index,item1.value)" v-for="(item1,index1) in item.detailList"
							:key="index1" class="scroll-view-item_H box_whbrc"
							:class="{'bgc_cfa526':array[0].SmallClassId==item1.value || array[1].SmallClassId==item1.value || array[2].SmallClassId==item1.value}">
							{{item1.title}}
						</view>
					</scroll-view>
				</view>
			</view>
			<!-- <scroll-view scroll-y="true" class="grarg" style="background-color: #1f2025;" :style="{'height': scrollerHeight}"> -->
			<view class="grarg theme_bg_vice_color">
				<view class="cu-card">
					<view @click="$goPage('../../pageB/script/info?id='+item.id)" class="margin-lr radius12 shadow padding-sm margin-tb-sm theme_bg_color"
						style="position: relative;" v-for="(item,index) in dataList"
						:key="index">
						<image v-if="item.status==1" src="../../static/icon/zd.png" class="zd" mode=""></image>
						<view class="flex justify-start">
							<image :src="$isHttp(item.picture)" lazy-load
								style="width: 160rpx;height: 220rpx;border-radius: 10rpx;" mode="aspectFill"></image>
							<view class=" margin-left-sm" style="width: 520rpx;">
								<view class="flex justify-start margin-top-xs">
									<view class="text-bold theme_text_color">{{item.name}}</view>
									<!-- <view class="cu-tag bg-yellow  sm round margin-left-sm">标签666</view> -->
								</view>
								<view class="margin-top-sm">
									<view v-for="(item1,index1) in item.smallClasses" :key="index1" v-if="index1<6"
										class="cu-tag sm round" style="background-color: #797979;color: #fff;">
										{{item1.small_name}}
									</view>
								</view>
								<view class="margin-top-sm flex justify-start" style="color: #b2b1b6;">
									<view class="flex justify-start align-center">
										<text class="cuIcon-friendfill text-yellow"></text>
										<view class="text-sm margin-left-xs">{{item.sex_type}}</view>
									</view>
									<view class="flex justify-start align-center margin-left-sm">
										<text class="cuIcon-timefill text-yellow"></text>
										<view class="text-sm margin-left-xs">{{item.hour}}小时</view>
									</view>
									<view class="flex justify-start align-center margin-left-sm">
										<text class="cuIcon-selectionfill text-yellow"></text>
										<view class="text-sm margin-left-xs">{{item.difficulty}}</view>
									</view>
								</view>
								<view class="flex justify-between  margin-top-sm">
									<view class="flex align-end text-yellow">
										<view class="text-sm ">会员价¥</view>
										<view class="text-lg text-bold">{{item.member_price}}</view>
										<view class="text-sm ">/位</view>
										<view class="text-lg text-gray" style="text-decoration:line-through">{{item.price}}</view>
									</view>
									<view 
										class="cu-btn bg-yellow sm round text-black">预约</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<empty-view slot="empty">
				<view class="text-center text-gray" style="padding-top: 300rpx;">
					<image src="../../static/icon/kong.png" style="width: 320rpx;height: 240rpx;" mode=""></image>
					<view>没有更多了</view>
				</view>
			</empty-view>
		</z-paging>
		<!-- </scroll-view> -->

		<!-- 筛选按钮 -->
		<drag-button :isDock="true" :text="''" :existTabBar="true" @btnClick="orderbyChange">
			<block slot="content">
				<view class="text-center" style="width: 100rpx;background-color: #292929;height: 100rpx;border: 1rpx solid #fff;border-radius: 50%;"><image src="/static/icon/search.png" style="width: 50rpx;height: 50rpx;margin: 20rpx 0 0 0;"></image></view>
			</block>
		</drag-button>
		
<!-- 		<view style="position: fixed;right: 30rpx;bottom: 200rpx;width: 100rpx;background-color: #292929;height: 100rpx;border: 1rpx solid #fff;border-radius: 50%;"
			@click="orderbyChange">
			<image src="../../static/icon/search.png" style="width: 50rpx;height: 50rpx;margin: 20rpx 0 0 20rpx;"
				mode=""></image>
		</view> -->

		<fjj-condition ref='condition' @touchmove.stop :color="color" :list="menuList" @result="resultConditon" />
		<!-- <view id="foot" class="cu-tabbar-height"></view> -->
	</view>
</template>

<script>
	import { shareMixins} from '@/common/mixins/share.js'
	import ZPagingMixin from '@/uni_modules/z-paging/components/z-paging/js/z-paging-mixin'
	export default {
		//注意这一步不要漏掉，必须注册mixins(如果全局引入了，就不要这一步，全局引入示例见main.js)
		mixins: [ZPagingMixin,shareMixins],
		data() {
			return {
				dataList: [],
				searchvalue: '',
				select: 1, //选择分类
				array: [],
				arrayVal: [],


				color: '#292929',
				hasChoose: false,
				menuList: [],
			};
		},
		watch: {
			arrayVal() {
				this.$refs.paging.reload()
			}
		},
		created() {
			this.menuList = this.vuex_menuList
			//判断是否登录
			this.$u.api.getUserIsbussiness({
				userId: this.vuex_user.id ? this.vuex_user.id : ''
			}).then(res=>{
				if(res.code==401){
					console.log(res)
					this.$login()
				}
			})
		},
		methods: {
			queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				// this.$request.queryList(pageNo, pageSize, this.tabIndex + 1, (data) => {
				// 	this.$refs.paging.complete(data);
				// })
				if (this.searchvalue == '') {
					this.$u.api.getScriptList({
						page: pageNo ? pageNo : 1,
						number: pageSize ? pageSize : 10,
						select: this.select,
						array: this.arrayVal
					}).then(res => {
						this.$refs.paging.complete(res.data);
					})
				} else {
					this.$u.api.getScriptByName({
						page: pageNo ? pageNo : 1,
						number: pageSize ? pageSize : 10,
						name: this.searchvalue
					}).then(res => {
						this.$refs.paging.complete(res.data);
					})
				}
			},
			search(e) {
				this.$refs.paging.reload()
			},
			searchChange(e) {
				this.searchvalue = e.detail
			},
			selectTag(index, SmallClassId) {

				//1. 首先我们要得到这个对象
				var tina = this.array.filter((s) => {
					return s.index == index;
				});
				
				var tina1 = this.array.filter((s) => {
					return s.SmallClassId == SmallClassId;
				});
				
				//2. 其次得到这个对象在数组中对应的索引
				var key = this.array.indexOf(tina[0])

				//3. 如果存在则将其删除，key > -1 代表存在
				key > -1 && this.array.splice(key, 1)
				if(tina1[0]==undefined){
					this.array.push({
						index,
						SmallClassId
					})
				}else{
					//2. 其次得到这个对象在数组中对应的索引
					var key1 = this.array.indexOf(tina1[0])
					
					//3. 如果存在则将其删除，key > -1 代表存在
					key1 > -1 && this.array.splice(key1, 1)
				}
				
				// 冒泡排序（从后向前）
				function sort(arr) {
					for (var j = 0; j < arr.length - 1; j++) {
						//两两比较，如果前一个比后一个大，则交换位置。
						for (var i = 0; i < arr.length - 1 - j; i++) {
							if (arr[i].index > arr[i + 1].index) {
								var temp = arr[i];
								arr[i] = arr[i + 1];
								arr[i + 1] = temp;
							}
						}
					}
				}
				sort(this.array)
				this.arrayVal = []
				for (var i = 0; i < this.array.length; i++) {
					this.arrayVal.push(this.array[i].SmallClassId)
				}

				console.info(this.array)
				console.info(this.arrayVal)
			},
			resultConditon(obj) {
				this.array=[]
				this.arrayVal=[]
				this.$refs.condition.visibleDrawer = false;
				this.hasChoose = obj.hasChoose;
				for (let var1 in obj.result) {
					if(obj.result[var1]!=""){
						this.arrayVal.push(obj.result[var1])
					}
				}
			},
			orderbyChange(obj) {
				this.$refs.condition.visibleDrawer = true;
			}
		},
	}
</script>

<style lang="scss" scoped>
	.zd {
		position: absolute;
		top: 0;
		left: 0;
		width: 60rpx;
		height: 55rpx;
		z-index: 1;
	}

	// .grarg {
	// 	position: absolute;
	// 	top: 225rpx;
	// 	bottom: 100rpx;
	// }

	.box_whbrc {
		width: 70rpx;
		height: 40rpx;
		border-radius: 30rpx;
		// background-color: #cfa526;
		margin-right: 10rpx;
		text-align: center;
		line-height: 40rpx;
	}

	.bgc_cfa526 {
		background-color: #cfa526;
	}

	.scroll-view_H {
		white-space: nowrap;
		width: 100%;
	}

	.scroll-view-item_H {
		display: inline-block;
	}
</style>
